package com.example.tanloadpic;

import android.graphics.Bitmap;
import android.net.Uri;
import android.widget.ImageView;


import static com.example.tanloadpic.utils.CommonUtils.checkMainThread;

public class RequestCreator {

    private TanLoadPic mTanLoadPic;
    private CompressConfig compressConfig;
    private RequestData mData;


    public RequestCreator(TanLoadPic tanLoadPic, Uri uri) {
        this.mTanLoadPic = tanLoadPic;
        mData = new RequestData(uri);
    }


    public RequestCreator(TanLoadPic tanLoadPic, int resourceId) {
        this.mTanLoadPic = tanLoadPic;
        mData = new RequestData(resourceId);
    }


    public RequestCreator setCompressConfig(CompressConfig compressConfig) {
        System.out.println("我看看你");
        if (compressConfig == null) {
            throw new NullPointerException("压缩compressConfig不应该为空指针！");

        }
        this.compressConfig = compressConfig;

        return this;
    }

    public void into(ImageView imageView) {
        checkMainThread();
        mData.imageView = imageView;
        mData.mCompressConfig = this.compressConfig;
        if (imageView == null) {
            throw new IllegalStateException("image view 不可以爲空");
        }

        mTanLoadPic.startExecute(mData);

    }

    public interface CompressConfig {
        Bitmap Compress(Bitmap bitmap);
    }


}
